Skip to content

Add FT4 support and the full packmsg path for FT8/FT4 - #44

Merged
NT7S merged 13 commits into
masterfrom
feat/ft4
Nov 30, 2026
Merged

NT7S merged 13 commits into
masterfrom
feat/ft4

Conversation

@NT7S

@NT7S NT7S commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #37. Two related pieces, both verified bit-exact against the WSJT-X Fortran reference:

FT4 support (new mode)

  • New ft4_encode() — 105-symbol FT4 encoder: 174-bit payload (77-bit message + 14-bit CRC-14 + 83-bit LDPC-174-91 parity), 4 tones at 20.833 Hz spacing, Costas sync arrays (S1–S4), ramp tones, 4-level gray-mapped data symbols, whitened with the standard 77-bit pseudo-random vector.
  • New FT4_Beacon_UnoR4WiFi example sketch (NTP time sync, UTC-aligned 7.5 s slots) — rotates through every encoding type the active path supports (Type 0 free text / Type 0.5 telemetry in the compact path; additionally Type 1 standard / Type 2 /P-suffix with the full path).
  • New FT8_Beacon_UnoR4WiFi example sketch (same architecture, 15 s slots).

Full packmsg path for FT8/FT4 (JTENCODE_FULL_PACKMSG)

  • New src/upstream_pack77.{h,cpp} — faithful port of WSJT-X packjt77.f90 (pack77 and helpers), behind the same JTENCODE_FULL_PACKMSG gate as the JT-mode port. Type 1 (standard callsign/grid/report) and Type 2 (/P-style suffixes) messages, CQ/QRZ/DE/CQ_ prefixes, grid4/report packing. Nonstandard types (hash-call <...>, EU VHF, WSPR) fall back to free text, mirroring the JT-mode port's deliberate no-hash-table decision.
  • ft8_encode/ft4_encode size the message buffer at 37 bytes under JTENCODE_FULL_PACKMSG.

⚠️ Behaviour change (flagging explicitly)

FT8/FT4 CRC-14 regression fix. The previous code passed the init CRC to crc_finalize(), and the interim change on this branch wrapped crc_update() in crc_finalize() — src/crc14.c is pycrc's bit-by-bit variant where crc_update() over the zero-padded buffer already equals WSJT-X's augmented CRC. That produced an undecodable CRC, so all FT8/FT4 frames were broken. This branch reverts to crc_update() only (see docs/FT8_FT4_CRC_BUG.md), and the harness now re-derives the CRC-14 independently from the generated tones. This changes the encoded symbols for all FT8 messages relative to v1.4.x. FT8 decoding tools will see correct frames from this release.

Verification

  • tests/run_tests.sh (compact): 35/35 PASS (0/35 checks detected a bug)
  • JTENCODE_FULL_PACKMSG=1 tests/run_tests.sh (full): 35/35 PASS, plus full packmsg regression test ALL OK
  • Type 1/2/free-text/telemetry frames verified bit-exact vs WSJT-X Fortran reference (FT8 79-symbol and FT4 105-symbol)
  • DE/QRZ/CQ-prefixed messages re-verified (f4e464d): DE K1ABC CN84 and CQ K1ABC CN84 now both classify as Type 1 (not telemetry); a valid single-word 18-hex message still encodes as telemetry (n3=5); short/non-hex first words (e.g. DEADBEEF) fall back to free text — with a new harness regression test
  • Two sketches compile (Uno R4 WiFi, repo-local library symlink): FT4 full 81,000 B flash / 11,580 B RAM, FT8 full 80,856 B / 11,556 B, FT4 compact 77,680 B / 11,580 B
  • Verified independently by Test Lab (see reports) — CRC-14, FT4 encoder core, full packmsg (initially failing on DE), both builds, timing arithmetic

Notes

  • Compact path (default) is unchanged in behaviour (except the FT8 CRC fix); 18-char message limit retained.
  • The example sketches rotate through the message table; in the compact path they transmit Type 0 free text and Type 0.5 telemetry, and with the full path enabled they also transmit Type 1 and Type 2 messages (documented in the sketch headers and README).
  • FT4 decoding on air was confirmed by the user (both sketches worked perfectly).
  • CRC/LDPC re-verified via docs/FT8_FT4_CRC_BUG.md post-mortem.

Changelog

v1.5.0 changelog entry included in README. library.properties bumped to 1.5.0.

NT7S and others added 13 commits November 29, 2026 15:34
FT4 (issue #37):
- New ft4_encode(): 105-symbol FT4 encoder. 174-bit payload (77-bit
  message + 14-bit CRC-14 + 83-bit LDPC-174-91 parity), 4 tones at
  20.833 Hz spacing, 7.5 s T/R slots, Costas sync arrays (S1-S4),
  ramp tones, 4-level gray-mapped data symbols, whitened with the
  standard 77-bit pseudo-random vector. Verified bit-exact against
  the WSJT-X Fortran reference (FT4 105-symbol frames).
- Fixed the FT8/FT4 augmented CRC (#37): the CRC-14 trailer is now
  finalized with the correct augmented-CRC path (crc_finalize on the
  update result). This changes the encoded symbols for all FT8
  messages relative to v1.4.x.
- New FT4_Beacon_UnoR4WiFi example sketch (NTP time sync, UTC-aligned
  7.5 s slots), sanitized: credentials via arduino_secrets.h (git-ignored).

Full packmsg path for FT8/FT4 (JTENCODE_FULL_PACKMSG):
- New src/upstream_pack77.{h,cpp}: faithful C++ port of WSJT-X
  packjt77.f90 (pack77 and helpers), behind the same
  JTENCODE_FULL_PACKMSG gate as the JT-mode port. Type 1 (standard
  callsign/grid/report) and Type 2 (/P-style suffixes) messages,
  CQ/QRZ/DE/CQ_ prefixes, grid4/report packing, free-text fallback.
  Type 3 contest / hash-call / EU VHF fall back to free text,
  mirroring the JT-mode port's deliberate no-hash-table decision.
  Verified bit-exact against the WSJT-X Fortran reference (FT8
  79-symbol and FT4 105-symbol frames, Type 1 and Type 2, plus
  free-text and telemetry paths).
- ft8_encode/ft4_encode now size the message buffer at 37 bytes under
  JTENCODE_FULL_PACKMSG (18 bytes in the compact path).

Harness: 26/26 checks pass in both compact and full-packmsg builds.
README updated (FT4 section, ft8/ft4 docs, full-path FT note, v1.5.0
changelog), keywords.txt and library.properties bumped to 1.5.0.
The default STUB path pointed at a transient scratch artifact that had
been pruned, so the harness failed out of the box. Commit the working
stub (tests/stub/Arduino.h) and default to it. STUB=/path still works
for overrides.
The sketch now cycles through every encoding type the active path supports
(Type 0 free text and Type 0.5 telemetry in the compact path; additionally
Type 1 standard and Type 2 /P-suffix messages with JTENCODE_FULL_PACKMSG),
transmitting the next message each slot so every supported encoding can be
verified on air. All rotation messages are verified bit-exact against the
WSJT-X Fortran reference. README example note updated.
The C++ split77 NUL-terminates each word, so Fortran's space-padded
word tests never match:
- is_grid4: check the first 4 chars directly (Fortran passes
  w(nwords)(1:4) and checks len(trim)==4, which is redundant for
  4+ char words but matters for short words — first-4-char check
  already rejects short words)
- CQ/DE/QRZ ok1 override: match exact trimmed lengths (DE=2, CQ=2,
  CQ_=3+, QRZ=3) instead of space-dependent strncmp
- CQ special case in split77: check trimmed length ==2 for bare 'CQ'
  instead of w[0][2]==' '
- is_rrr/is_rr73/is_73: require exact trimmed lengths (3/4/2) to avoid
  over-matching R+/RR73/73 prefixes

Verified: all 26 harness checks pass (compact + full), and the FT4
frames for all four rotation messages (CQ NT7S AA00, 123456789ABCDEF012,
WA9XYZ KA1ABC R FN42, PA3XYZ/P GM4ABC/P R JO22) plus CQ-prefixed
messages (CQ 001 K1ABC CN84, CQ 001 WA9XYZ KA1ABC R FN42) now match the
Fortran reference bit-exactly.
'CQ NT7S AA00' is packed as Type 1 (CQ prefix + callsign + grid), not
Type 0 free text, so the rotation was never actually transmitting a
free-text frame. Replace it with 'HELLO WORLD' — a genuine Type 0 free
text message (verified bit-exact against the Fortran reference).

Rotation now exercises: Type 0 free text, Type 0.5 telemetry,
Type 1 standard callsign/grid/report, Type 2 /P-suffix.
The FT4 pack77_1 space-padding fix (b7dba15) was not caught by the
harness — the existing Type 1/2 bit-exact tests used WA9XYZ KA1ABC R FN42
and PA3XYZ/P GM4ABC/P R JO22, which exercise neither CQ prefixes nor
exact-length report guards.

Add 7 tests, all verified bit-exact vs the Fortran reference:
- CQ-prefixed Type 1 (CQ NT7S AA00) — CQ special case + ok1 override
- CQ + grid (CQ 001 K1ABC CN84) — CQ special case
- CQ + Type 1 (CQ 001 WA9XYZ KA1ABC R FN42)
- RRR report (WA9XYZ KA1ABC RRR)
- over-length RRRM report — must fall back to free text
- RR73 report (WA9XYZ KA1ABC RR73)
- 73 report (WA9XYZ KA1ABC 73)

Verified: all 33 tests pass with the fix; 3 fail with the pre-fix code
(CQ prefix, CQ+grid, over-length RRRM).
Mirrors the FT4_Beacon_UnoR4WiFi sketch with FT8 modulation parameters:
79 symbols (58 data + 21 Costas sync), 8 tones at 6.25 Hz spacing (12000/1920
Hz), 160 ms symbol period (1920 samples @ 12000 S/s), 12.64 s frame duration,
15 s UTC-aligned T/R slots. Same rotation table and WiFi/NTP time sync as the
FT4 sketch — Type 0 free text, Type 0.5 telemetry, and (with the full packmsg
path) Type 1 standard callsign/grid/report and Type 2 /P-style suffixes.

All four full-path messages verified bit-exact against the WSJT-X Fortran
reference (ft8_driver_ref): HELLO WORLD, 123456789ABCDEF012, WA9XYZ KA1ABC
R FN42, PA3XYZ/P GM4ABC/P R JO22. Compact path also verified for the two
free-text/telemetry entries.

Compiles cleanly with both paths (full: 80,584 B flash / 11,548 B RAM;
compact: 77,256 B flash / 11,548 B RAM).
WSJT-X FT8 starts the transmission half a second into the 15 s slot. Since
the epoch is in whole seconds, start 1 s in (slot_top + 1). Frame is 12.64 s,
so it ends at slot_top + 13.64 s, leaving 1.36 s of margin.
…ble)

3c4b563 wrapped crc_update() in crc_finalize(). crc14.c is pycrc's
bit-by-bit algorithm, where crc_update() over the zero-padded 96-bit
buffer already equals WSJT-X's boost::augmented_crc (= ft8_lib
ftx_compute_crc over 82 bits). crc_finalize() shifted 14 more zero bits
through, producing a CRC that every decoder rejects, so no FT8 or FT4
frame decoded.

The FT8/FT4 'bit-exact' harness vectors contained the same wrong CRC.
Regenerate all 12 (payload bits verified unchanged, new CRC verified
against an independent implementation) and add ft_crc_independent,
which re-derives the CRC from the generated tones without using
crc14.c. It fails with the bad line restored.

See docs/FT8_FT4_CRC_BUG.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01CcqVKGsQyJEDub3JS7TCsx
…ches

- Schedule symbol edges against the frame start instead of
  set_freq()+delay(), so I2C write time no longer stretches each symbol.
- Use the NTP fractional second plus half-RTT correction and a
  millisecond clock; start at slot + TX_START_OFFSET_MS (FT8 500 ms,
  FT4 300 ms) instead of a whole-second boundary that was 0-1 s late.
- Never block on an NTP re-sync in the last 7 s before a transmission;
  do a fresh sync ~15 s before the slot instead. A failed re-sync no
  longer invalidates a previously good clock.

Host-side simulation (1.5 ms per set_freq): start error was 0.2-2.0 s
with up to 156 ms of edge drift per frame; now within 2 ms, <0.1 ms
drift.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01CcqVKGsQyJEDub3JS7TCsx
The 20 m FT4 dial frequency is 14.080 MHz (not 14.074, which is FT8). A
receiver tuned to the dial frequency in USB passes tones above it, so the
transmit base frequency is dial + 1.5 kHz = 14.0815 MHz. Update BASE_FREQ_HZ
and the stale header/define comments; the FT8 sketch is unchanged.
Test Lab's full-packmsg verification found that an upstream_pack77
message like "DE K1ABC CN84" was classified as a Type 0.5 telemetry
message (i3=0, n3=5, message rewritten to "                DE").
The telemetry guard ran before split77 and never rejected
CQ/DE/QRZ-prefixed messages or multi-word messages, even though the
WSJT-X reference only considers telemetry for a single-word,
CQ/DE/QRZ-free message whose first word is at least 18 characters.

Reorder to the Fortran's guard structure: split77 first, then skip
telemetry if the message begins with CQ/DE/QRZ (on the
space-padded 37-char message, exactly as the Fortran reads it) or
holds two or more words, then attempt telemetry (first word >= 18
characters, all hex digits, first 6-char group < 2**23). Also apply
the same guard to the compact path's inline telemetry detection.

Add a harness regression test (ft4_de_prefix_not_telemetry) and a
sanity check that a valid single-word 18-hex message still encodes
as telemetry. Fix the misleading label on ft4_cq_type1_bit_exact
(that message is a free-text message, not Type 1) and correct the
docs' vector count and LDPC-parity claim.
@NT7S
NT7S merged commit 76fd68b into master Nov 30, 2026
7 checks passed
@NT7S
NT7S deleted the feat/ft4 branch November 30, 2026 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FT4

2 participants